//
// system timer fired
//
// RFTimerFired.cpp
//
// wangsihong@live.com
//

#include "RFTimerFired.h"

namespace Rooftop {

SystemTimerFired* SystemTimerFired::p_instance = NULL;

SystemTimerFired* SystemTimerFired::getInstance()
{
    if (!p_instance)
        p_instance = new SystemTimerFired();
    return p_instance;
}

void SystemTimerFired::fired()
{
    if (m_isRunning){
        EventManager::getInstance()->dispachEvent(m_event);

        boost_timer.expires_at(boost_timer.expires_at() + boost::posix_time::milliseconds(m_timerFiredTimeMS));
        boost_timer.async_wait(boost::bind(&SystemTimerFired::fired, this));
    }
}

void SystemTimerFired::start()
{
    boost_timer.async_wait(boost::bind(&SystemTimerFired::fired, this));
    m_isRunning = true;
    boost_io.run();
}

void SystemTimerFired::stop()
{
    m_isRunning = false;
}

}

